package com.ywl.study.sharding.study05.algorithm;

import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

import java.util.ArrayList;
import java.util.Collection;

public class ModuloHintShardingAlgorithm implements HintShardingAlgorithm<Long> {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, HintShardingValue<Long> hintShardingValue) {
        Collection<String> result=new ArrayList<>();
        for(String each : availableTargetNames){
            Collection<Long> values=hintShardingValue.getValues();
            for (Long value : values) {
                if (each.endsWith(String.valueOf(value % 2))) {
                   result.add(each);
                }
            }
        }
        return result;
    }


}
